<?php
namespace Chat\Controller;


use \GatewayWorker\Lib\Gateway;
class MessagesController extends BaseController{
    
    public function query()
    {
        $user_id = $this->user_id;
        $to_uid = I('to_uid', 0);
        $last_id = I('last_id', 0);
        $model = D('Message');
        $where = "((`from_uid`={$user_id} AND `to_uid`={$to_uid}) OR (`from_uid`={$to_uid} AND `to_uid`={$user_id}))";
        if($last_id){
            $where .= " AND `id`<{$last_id}";
        }
        $where .= " AND `status` = 1";
        $sql = "SELECT `id`,`from_uid`,`msg_type`,`content`,`create_time` as `time` FROM __USER_MESSAGE__ WHERE {$where} ORDER BY `id` DESC LIMIT 8";
        $list = $model->query($sql);
        if($list){
            foreach ($list as $key => &$row) {
                
            }
        }
        $this->ajaxReturn(['status'=>1, 'msg'=>'ok', 'list'=>$list/*, 'sql'=>$model->getLastSql()*/]);
    }
}